package cn.zwx.infra.svc.controller.sms;

import cn.zwx.base.entity.ResponseEntity;
import cn.zwx.base.exception.BizWrapException;
import cn.zwx.base.utils.PageUtil;
import cn.zwx.infra.svc.dto.SmsChannelPageDTO;
import cn.zwx.infra.svc.dto.SmsChannelSaveDTO;
import cn.zwx.infra.svc.dto.SmsChannelUpdateDTO;
import cn.zwx.infra.svc.service.sms.SmsChannelService;
import cn.zwx.infra.svc.vo.SmsChannelSimpleVO;
import cn.zwx.infra.svc.vo.SmsChannelVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author zhangwenxue
 */
@RestController
@Api(tags = "短信渠道关相关接口")
@RequestMapping("infra/sms/")
public class SmsController {

    private final SmsChannelService smsChannelService;

    public SmsController(SmsChannelService smsChannelService) {
        this.smsChannelService = smsChannelService;
    }

    @PostMapping("/create")
    @ApiOperation("创建短信渠道借口")
    public ResponseEntity<Long> createSmsChannel(@Valid @RequestBody SmsChannelSaveDTO dto){
        return ResponseEntity.success(smsChannelService.createSmsChannel(dto));
    }

    @PutMapping("/update")
    @ApiOperation("更新短信渠道")
    public ResponseEntity<Boolean> updateSmsChannel(@Valid @RequestBody SmsChannelUpdateDTO dto) throws BizWrapException {
        return ResponseEntity.success(smsChannelService.updateSmsChannel(dto));
    }
    @DeleteMapping("/delete")
    @ApiOperation("删除短信渠道")
    public ResponseEntity<Boolean> deleteSmsChannel(@Valid@NotNull(message = "编号不能为空")
                                             @ApiParam(value = "编号",required = true)
                                             @RequestParam("id") Long id) throws BizWrapException {
        return ResponseEntity.success(smsChannelService.deleteSmsChannel(id));
    }

    @GetMapping("/get")
    @ApiOperation( "获得短信渠道")
    public ResponseEntity<SmsChannelVO> getSmsChannel(@Valid@NotNull(message = "编号不能为空")
                                               @ApiParam(value = "编号",required = true)
                                               @RequestParam("id") Long id) {
        return ResponseEntity.success(smsChannelService.getSmsChannel(id));
    }

    @GetMapping("/page")
    @ApiOperation("获得短信渠道分页")
    public ResponseEntity<PageUtil<SmsChannelVO>> getSmsChannelPage(@Valid SmsChannelPageDTO dto){
        return ResponseEntity.success(smsChannelService.getSmsChannelPage(dto));
    }

    @GetMapping({"/list-all-simple", "/simple-list"})
    @ApiOperation("获得短信渠道精简列表 包含被禁用的短信渠道")
    public ResponseEntity<List<SmsChannelSimpleVO>> getSimpleSmsChannelList(){
        return ResponseEntity.success(smsChannelService.getSimpleSmsChannelList());
    }
}
